package Algorithm.set;

import java.util.ArrayList;
import java.util.List;

//子集
public class SubSet {
    List<List<Integer>> ans;
    public List<List<Integer>> subsets(int[] nums) {
        ans = new ArrayList<>();
        ans.add(new ArrayList<>());
        dfs(nums,0,new ArrayList<>());
        return ans;
    }

    public void dfs(int[] nums,int x,List<Integer> list){
        if (x==nums.length){
            return;
        }
        for(int i = x;i<nums.length;i++){
            list.add(nums[i]);
            ans.add(new ArrayList<>(list));
            dfs(nums,i+1,list);
            list.remove(list.size()-1);
        }
    }

    public static void main(String[] args) {
        SubSet test = new SubSet();
        List<List<Integer>> subsets = test.subsets(new int[]{1,2,3,4});
        for (List<Integer> subset : subsets) {
            for (Integer integer : subset) {
                System.out.print(integer+" ");
            }
            System.out.println();
        }
    }
}
